package com.tanhua.mangement.controller;

import com.tanhua.common.utils.NoAuthorization;
import com.tanhua.dubbo.server.enums.LogType;
import com.tanhua.mangement.service.ManageLogsService;
import com.tanhua.mangement.vo.PageLogResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("manage")
@Slf4j
public class ManageLogsController {

    @Autowired
    private ManageLogsService manageLogsService;


    /**
     * 日志翻页管理
     *
     * @param
     * @return
     */
    @NoAuthorization
    @GetMapping("logs")
    public ResponseEntity<PageLogResult> queryLogs(@RequestParam(value = "page", defaultValue = "1") Integer page,
                                                   @RequestParam(value = "pagesize", defaultValue = "5") Integer pagesize,
                                                   @RequestParam(value = "sortProp") String sortProp,
                                                   @RequestParam(value = "sortOrder") String sortOrder,
                                                   //@RequestParam(value = "type") Integer type,
                                                   @RequestParam(value = "uid") Long uid) {

        try {
            PageLogResult pageLogResult = manageLogsService.queryLoginLogList(uid, page, pagesize, sortProp, sortOrder, LogType.LOGIN);
            //判断是否为null
            if (pageLogResult != null) {
                return ResponseEntity.ok(pageLogResult);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }
}
